<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>申请书编辑</title>
<script type="text/javascript" src="${res}/js/jquery/jquery.form.js"></script>
<script type="text/javascript"
	src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript"
	src="${res}/js/validate/irisvalidator.js"></script>
<script type="text/javascript"
	src="${res}/js/keyword/keywordtips.js"></script>	
<script type="text/javascript"
	src="${res_app}/js/app/proposal/irisPrpPrepare.js"></script>



<script type="text/javascript">
$(function(){
	queryflex();
});
/**
 * 申请书提交方法
 */


var ctxpath = "${ctx}";
var prcWin = new progressWin("${res}");//初始化遮罩层
/**
 * 页面初始化方法 所有的都定义在里面
 */
$(document).ready (function() {
	$("#wbox1").click(function() {
		check("check");
	});
	
	$("#wbox2").click(function() {
		
		check("check");
		
	});
	
	initControl();
	
	$("table.t_css").not("[id='finances']").not("[id='checkbox_table_']").not("[id='budgetsMsg2']").not("[id='basicInfo']").each(function(){
		$(this).find("tr:even").addClass("li_1");
		$(this).find("tr:odd").addClass("li_2");
	});
	$("table").addClass("table01");
	$("#checkbox_table_").removeClass("table01");
	$("#feaReport_upload").removeClass("table01");
    $('div').find("[id^='checkbox_dyn_']").find("tr").removeClass("li_1").removeClass("li_2");
    $('div').find("[id^='checkbox_dyn_']").find("td").css("border",'0px solid');
	
	window.setInterval("checkPdfStatus()", "10000");//检验申请书的pdf
});

$(document).ready(function() {
	fileInit("feaReport_upload","DOC,DOCX,PDF,WPS");
	fileInit("prpContent_upload","PDF,DOC,DOCX,WPS",null,"");
	
	//fileInitAttach("attachAdd", "JPG,PDF", null, 20, "{'JPG':'3072','PDF':'3072'}");
	$("#prpContent_upload").find(".file").hide();//隐藏文本框
});


$(document).ready(function() {
	$("#org").attr("disabled","true");
	initDepartForComplete("org");
	 initControl();
});

/**
 * 申报日期默认为当前日期
 */
 var show_year3_tipInfo="";
 var show_yanfa_tipInfo="";
$(document).ready(function() {


	var nowDate = '${sercverSysDate1}';
    if($("#submit_date").val()==""){
	   $("#submit_date").val(nowDate);
    }

	 show_year3_tipInfo=$('#show_year3_tipInfo').val();
	 show_yanfa_tipInfo=$('#show_yanfa_tipInfo').val();
    
});

	/**
	* 以一行为单位 验证表格的完整性 当该行input中有一个填写 则改行其他input也必须填写完整
	* @param tblId 表格id
	* @param baseLineNum 要忽略的行的数量 如：表头
	*/
	function validateByTrComplete(tblId,title,baseLineNum){
		$("#"+tblId).find("tr").each(function(index){
			var cnt = 0;
			$(this).find("input").not(':radio').each(function(){
				var val = $(this).val();
				if ($.trim(val) == '' || val == undefined )
				{
					cnt = parseInt(cnt) +1;
				}
			});
			var lineNum = index - baseLineNum + 1;
			if ( cnt == $(this).find("input").not(':radio').length){  //该行所有的input都未填写
				//validate($(this),title+"第"+lineNum+"行");
			}else if (cnt == 0)  //已全填写完整，进行逻辑校验
			{
				validate($(this),title+"第"+lineNum+"行");
			}
			else 
			{
				irisValaddMsg(title + "第"+lineNum+"行请完整填写");	
			}
		});
	}

	/**
	 * 填写检查
	 */
function check(type){
	setTotalAmt();
	/* validate($("#fragment-tab1"),"基本信息"); */
	validate($("#basicInfo"),"基本信息-->基本信息"); 
	 show_year3_tipInfo=$('#show_year3_tipInfo').val();
	 show_yanfa_tipInfo=$('#show_yanfa_tipInfo').val();
	if(show_year3_tipInfo=='2'){
		validate($("#product_last_3_year1"),"基本信息-->近3年经营情况"); 
	}
	
	validateByTabRow($("#tblUnits"),"基本信息-->列出参与单位",0);
	validate($("#leadOrg"),"基本信息-->牵头单位信息");
	var unit_type_value = $('#unit_type_value').val();
	if ( unit_type_value == 2 || unit_type_value == 3 ) 
	 {
		validateByTabRow($("#tblBrands"),"基本信息-->自主品牌创建情况",0);
		validateByTabRow($("#tblTecSelf"),"基本信息-->近3年自主研发产品（技术）情况",1);
		if(show_yanfa_tipInfo=='2'){
			validate($("#lead_org_guarantee1"),"基本信息-->牵头单位在团队建设中的支撑保障作用");
		}
		validate($("#leaderOrgGuarentee"),"基本信息-->牵头单位在团队建设中的支撑保障作用");
	 }
	
	
	validate($("#basicInfo2"),"基本信息-->联系人信息");
	validate($("#basicInfo3"),"基本信息-->人员结构基本情况");
	
	validateByTrComplete("basicInfo4","基本信息-->依托载体情况",2);
	validate($("#goal_summary"),"基本信息");
	
	
	validate($("#person1"),"人员情况-->团队带头人基本情况");
	var submitPsn = $("#submit_psn").parent("td").parent("tr");
	var zh_name = submitPsn.find("span[name$='zh_name']").text();
	var major = submitPsn.find("span[name$='major_work']").text();
	var birthday = submitPsn.find("span[name$='birthday']").text();
	var position = submitPsn.find("span[name$='position']").text();
	var educate_name = submitPsn.find("span[name$='educate_name']").text();
	var work = submitPsn.find("span[name$='work']").text();
	var org_name = submitPsn.find("span[name$='org_name']").text();
	var prof_title_name = submitPsn.find("span[name$='prof_title_name']").text();
	if (zh_name=="" || major=="" || birthday=="" || position=="" || educate_name=="" || work=="" || org_name=="" || prof_title_name=="") {
		irisValaddMsg("人员情况-->项目负责人基本信息 (团队核心成员基本情况第一条)不完整");
	} 
	validateByTabRow($("#zh_persons"),"人员情况-->团队核心成员基本情况",2);
	validateByTabRow($("#tblLearn"),"人员情况-->学习经历",1);
	validateByTabRow($("#tblWork"),"人员情况-->工作经历",1);
	validateByTabRow($("#tblReward"),"人员情况-->获得重要科研学术奖励情况",0);
	validateByTabRow($("#tblSupport"),"人员情况-->获得人才计划支持情况",0);
	validateByTabRow($("#tblPeriodical"),"人员情况-->国内外学术组织及重要学术期刊任职情况",0);
	validate($("#tblresume"),"人员情况");
	
	validateByTabRow($("#tblForegoer"),"科研情况-->团队带头人主持的主要科研任务情况",0);
	validateByTabRow($("#tblCore"),"科研情况-->团队核心成员主持的主要科研任务情况",0);
	validateByTabRow($("#tblConference"),"科研情况-->团队带头人获得重要科研学术奖励情况",0);
	validateByTabRow($("#tblConferencehx"),"科研情况-->团队核心成员获得重要科研学术奖励情况",0);
	validateByTabRow($("#tblPatent"),"科研情况-->团队带头人获得授权专利情况",0);
	validateByTabRow($("#tblPatenthx"),"科研情况-->团队核心成员获得授权专利情况",0);
	validateByTabRow($("#tblReport"),"科研情况-->团队带头人参加重要国际学术会议报告情况",0);
	validateByTabRow($("#tblReporthx"),"科研情况-->团队核心成员参加重要国际学术会议报告情况",0);
	validateByTabRow($("#tblWriting"),"科研情况-->团队带头人拥有著作情况",0);
	validateByTabRow($("#tblWritinghx"),"科研情况-->团队核心成员拥有著作情况",0);
	validateByTabRow($("#tblThesis"),"科研情况-->团队带头人发表论文情况",0);
	validateByTabRow($("#tblThesishx"),"科研情况-->团队核心成员发表论文情况",0);
	validateByTabRow($("#tblAchievement"),"科研情况-->团队的标志性成果和产业化情况",0);
	validate($("#tblresume10"),"科研情况");
	validate($("#tblresume11"),"科研情况");
	
	
	validate($("#goal1"),"团队建设计划");
	validateByTabRow($("#tblMileStones"),"团队建设计划-->主要研发项目规划",1);
	validateByTabRow($("#tblTalentPlan"),"团队建设计划-->人才培养规划",1);
	validate($("#goal2"),"团队建设计划");
	validate($("#budgetsMsg"),"经费信息");
	validate($("#budgetsMsg1"),"经费信息");
	validate($("#budgetsMsg2"),"经费信息");
	validate($("#fundInfo"),"经费信息-->计划新增投资支出情况");
	irisJqValEmpty($("#fundInfo"),"经费信息-->计划新增投资支出情况请完整填写");
	if ( irisJqValEmpty2($("#performances"),"项目绩效-->项目绩效目标表请完整填写") == 0){
		validate($("#performances"),"项目绩效");
	}
    prp_attach();
	if(!valResult()){
		irisValShowMsg($("#wbox1"));
		return false;
	}
	if(type=="check"){
		showBox($("#wbox1"), "300px", "200px", "检查通过","1:所有检查全部合格");
	}
	return true;
}


			/**
			*
			* @param objId
			* tableId
			* @param rowNum
			* 最低行数,可以不写
			*/
			function validateByTabRow(obj, title, rowNum) {
				if (obj.attr('id') == 'tblTecSelf')
				{
					if ((obj.find("tr").length - 4) < rowNum)
						irisValaddMsg(messageTip.rowNum.replace("[name]", title).replace("[num]", rowNum));
						obj.find("tr").each(function(index) {
						if (index >= 4) 
						{
							rtitle = messageTip.rowIndex.replace("[name]", title).replace("[index]", index - 3);
							validate($(this), rtitle);
						}
					});
					
				}else{
					if ((obj.find("tr").length - 2) < rowNum)
						irisValaddMsg(messageTip.rowNum.replace("[name]", title).replace("[num]", rowNum));
						obj.find("tr").each(function(index) {
						if (index >= 2) 
						{
							rtitle = messageTip.rowIndex.replace("[name]", title).replace("[index]", index - 1);
							validate($(this), rtitle);
						}
					});
				}		
			} 



function setTotalAmt(){
	/* $('#total_amt').val($("#input_total").val()); */
	$('#request_amt').val($("#source_apply").val());
}

</script>

</head>
<body>

	<c:set var="xmlstr" value="${xmlData}" />
	<x:parse xml="${xmlstr}" var="xmlData" />
	<input type="hidden" id="childDiv" class="thickbox"/>
	<input type="hidden" id="filePath" value="${ctx}/file/ajax-filedownload?fileCode=" />
	<input type="hidden" id="menuId" value="${param.menuId}" />
	<input type="hidden" id="sysDate" value="${sercverSysDate}" />
	
	<div id="showMessage"></div>
	<div id="content">
		
		<cpt:helpTips key="prpedit" id="prpEditTips"></cpt:helpTips>
		<div class="clear_h15"></div>
		<div class="word_box" id="mainDiv">
			<div class="bar_btn">
				<span class="left"> 
					<c:set var="grantCode"><x:out select="$xmlData/data/proposal/grant_code" /></c:set>
					<c:set var="flag_shizhi"><x:out select="$xmlData/data/proposal/flag_shizhi" /></c:set>
					<input name="Submit" type="button" class="button_01" value="保存" onclick="saveAction()" /> 
					&nbsp; <c:if test="${not empty fbl.pdfViewUrl}"><input name="Submit" type="button" class="button_01" value="下载PDF"  onclick="genPdfAction()"/></c:if>
					<security:authorize ifNotGranted="A_DAILU_PROPOSAL">
					&nbsp; <input name="Submit" type="button" class="button_01"	value="提交给单位管理员" onclick="submitAction()" />
					</security:authorize>
					<security:authorize ifAnyGranted="A_DAILU_PROPOSAL">
					&nbsp; <input name="Submit" type="button" class="button_01"	value="提交到归口管理部门" onclick="submitAction()" />
					</security:authorize> 
					&nbsp; <input name="Submit" type="button" class="button_01" value="返回" onclick="backToList()" />
				</span>
				<span class="right"> 
					<input title="填写检查" class="btn_inspect" type="button" id="wbox1"/>
				</span>
					<c:set var="sub_grant_code"><x:out select="$xmlData/data/proposal/sub_grant_code" /></c:set>
					
			</div>
			<div class="bar_b">
				<input type="hidden" id="pdfStatus" value="${pdfStatus}" />
				<span class="right">版本号：<span name="proposal/prp_version" id="prp_version"><x:out select="$xmlData/data/proposal/prp_version" /></span></span>
			</div>
			<form method="post" id="mainForm">
				<input type="hidden" value="${grantCode}" id="grantCode"
					name="grantCode"> 
				<input type="hidden" value="${posCode}" id="posCode" name="posCode"> 
				<input type="hidden" value="<iris:des3 code="${posCode}"></iris:des3>" id="posCodeDes" name="posCodeDes">
				<input type="hidden" value="<iris:des3 code="${fbl.pdfCode}"></iris:des3>" id="pdfCodeDes" name="pdfCodeDes">  
				<input type="hidden" value="${xmlData}" id="xmlData" name="xmlData">
				<input type="hidden" value="${fbl.pdfCode}" id="pdfCode" name="pdfCode"> 
				<input type="hidden" value="${flag_shizhi}" id="flag_shizhi" name="proposal/flag_shizhi"> 
			</form>
				<div class="word_title">
					<c:set var="statYear">${statYear}</c:set>
					<c:if test="${empty statYear}">
						<c:set var="statYear"><x:out select="$xmlData/data/proposal/stat_year" /></c:set>
					</c:if>
					<input type="hidden" name="proposal/stat_year" value="${statYear}">
					<span name="proposal/grant_name" ><x:out select="$xmlData/data/proposal/grant_name" /></span>-项目申请书 (<span name="proposal/stat_year">${statYear}</span>年)<br />					
					(<span name="proposal/sub_grant_name"><x:out select="$xmlData/data/proposal/sub_grant_name" /></span>)
					<input type="hidden" name="proposal/manage_category" value="<x:out select="$xmlData/data/proposal/manage_category" />" />
					<%-- <input type="hidden" name="proposal/sub_grant_name" value="<x:out select="$xmlData/data/proposal/sub_grant_name" />" /> --%>
					<input type="hidden" name="proposal/grant_code" value="<x:out select="$xmlData/data/proposal/grant_code" />" />  <input type="hidden" name="proposal/psn_code" value="<x:out select="$xmlData/data/proposal/psn_code" />" />
					<input type="hidden" id="grant_no" name="proposal/grant_no" value="<x:out select="$xmlData/data/proposal/grant_no" />" />							
					<input type="hidden" name="proposal/sub_grant_code" value="<x:out select="$xmlData/data/proposal/sub_grant_code" />" />
					<input name="proposal/register_area_code" type="hidden" value="<x:out select="$xmlData/data/organizations/organization[@submit_org='1']/area_value" />" />
		            <input name="proposal/register_area_name" type="hidden" value="<x:out select="$xmlData/data/organizations/organization[@submit_org='1']/area_name" />" />
					<input type="hidden" id="sub_grant_no" name="proposal/sub_grant_no" value="<x:out select="$xmlData/data/proposal/sub_grant_no" />" />
					<input type="hidden" name="proposal/help_grant_code" value="<x:out select="$xmlData/data/proposal/help_grant_code" />" />
					<input type="hidden" id="help_grant_no" name="proposal/help_grant_no" value="<x:out select="$xmlData/data/proposal/help_grant_no" />" />
					<c:set var="formCode"><x:out select="$xmlData/data/proposal/form_code" /></c:set>
					<c:set var="nature_value"><x:out select="$xmlData/data/organizations/organization[@submit_org='1']/nature_value" /> </c:set>
					<c:if test="${empty formCode}"><c:set var="formCode" value="${param.formCode}"></c:set></c:if>
					<input type="hidden" name="proposal/form_code" value="${formCode}" />
				    <input type="hidden" name="proposal/request_amt" 	id="request_amt" value="<x:out select="$xmlData/data/proposal/request_amt"/>">
					<input type="hidden" name="proposal/year" value="${year}" />
							
				 <!-- 公用的配置界面 -->
				    <jsp:include page="./prpeditmain_public.jsp"><jsp:param value="${xmlstr}" name="xmlstr" /></jsp:include>
				</div>
				<div id="tabnav">
					<ul>
						<li class="down" id="tab1" onclick="changeTab(this.id)">
						    <a href="###"><span>基本信息</span></a>
						</li>
						
						<li  id="tab2" onclick="changeTab(this.id)">
						    <a href="###"><span>人员情况</span></a>
						</li>
						
						<li id="tab3" onclick="changeTab(this.id)" >
						    <a href="###"><span>科研情况</span></a>
						</li>
						<li id="tab4" onclick="changeTab(this.id)" >
						    <a href="###"><span>团队建设计划</span></a>
						</li>
						
						<li id="tab5" onclick="changeTab(this.id)">
						    <a href="###"><span>经费信息</span></a>
						</li>
						<li id="tab6" onclick="changeTab(this.id)" >
						    <a href="###"><span>项目绩效</span></a>
						</li>
						<li id="tab7" onclick="changeTab(this.id)" >
						    <a href="###"><span>附件列表</span></a>
						</li>
					</ul>
				</div>
				<div class="tab_box" id="fragment-tab1">
					<jsp:include page="../info/prpInfoEdit_zdkjcxtd.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
						<jsp:param value="${grantName}" name="grantName" />
					</jsp:include>
				</div>
				
				<div class="tab_box" id="fragment-tab2" style="display: none">
					<jsp:include page="../psn/prpzhpsn_zdkjcxtd.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
					</jsp:include>
				</div>
				
				<div class="tab_box" id="fragment-tab3" style="display: none">
					<jsp:include page="../knowledge/prpknowledge_zdkjcxtd.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
					</jsp:include>
				</div>
				<div class="tab_box" id="fragment-tab4" style="display: none">
					<jsp:include page="../goal/prpgoaledit_zdkjcxtd.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
					</jsp:include>
				</div>
				<div class="tab_box" id="fragment-tab5" style="display: none">
					<jsp:include page="../fund/prpfundedit_zdkjcxtd.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
					</jsp:include>
				</div>
				<div class="tab_box" id="fragment-tab6" style="display: none">
					<jsp:include page="../performance/prpperformanceedit_zdkjcxtd.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
					</jsp:include>
				</div> 
				<div class="tab_box" id="fragment-tab7" style="display: none">
					<jsp:include page="../attach/prpAttachEdit_by_common_rc.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
						<jsp:param value="（附件材料加盖公章）" name="remark" />
					</jsp:include>
				</div>
				
				
			<div class="bar_btn02">
				<span class="left"> 
					<input name="Submit" type="button" class="button_01" value="保存" onclick="saveAction()" /> 
					&nbsp; <c:if test="${not empty fbl.pdfViewUrl}"><input name="Submit" type="button" class="button_01" value="下载PDF"  onclick="genPdfAction()"/></c:if>
					<security:authorize ifNotGranted="A_DAILU_PROPOSAL">
					&nbsp; <input name="Submit" type="button" class="button_01"	value="提交给单位管理员" onclick="submitAction()" />
					</security:authorize>
					<security:authorize ifAnyGranted="A_DAILU_PROPOSAL">
					&nbsp; <input name="Submit" type="button" class="button_01"	value="提交到归口管理部门" onclick="submitAction()" />
					</security:authorize> 
					&nbsp; <input name="Submit" type="button" class="button_01" value="返回" onclick="backToList()" /> 
				</span>
				<span class="right"> 
					<input title="填写检查" class="btn_inspect" type="button" id="wbox2"/>
				</span>
			</div>
		</div>
		<div class="clear_h15"></div>
	</div>
</body>

</html>